<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>Insert title here</title>
	<script type="text/javascript"
	src="/resources/js/common/jquery-1.11.3.min.js"></script>
	<script type="text/javascript" src="/resources/js/common/common.js"></script>
	<script type="text/javascript" src="/resources/js/common/template.js"></script>
</head>
<body>

	<h1>uesr list page</h1>
	<input type="text" name="name" id="searchName">
	<button onclick="loadDataWithPage(1)">搜索</button>
	<div id="outputDiv"></div>
	<textarea id="cart_jst" style="display: none;">
		{if data.totalRow==0}没有数据{/if}
		{if data.totalRow!=0}
		<table border="1">
			<tr>
				<td>姓名</td>
				<td>年龄</td>
				<td>操作</td>
			</tr>
			{for user in data.list}
			<tr>
				<td>\${user.name}</td>
				<td>\${user.age}</td>
				<td>
					<a href="/user/editUI/\${user.id }">修改</a>
					<a
					href="javascript:if(confirm('确定要删除\${user.name}吗？')){window.location.href='/user/delete/\${user.id }';}">删除</a>
				</td>
			</tr>
			{/for}
		</table>
		{/if}
	</textarea>
	<div id="pageShow"></div>
	<textarea id="pageData" style="display: none;">
	</textarea>



	<br>
	<a href="/user/editUI">新建用户</a>
	<a href="/">返回主页</a>

	<script type="text/javascript">
	$(function() {
		loadDataWithPage(1);
	});
	function loadDataWithPage(pageNum) {
		$.ajax({
			type : "POST",
			url : "/user/list",
			data : {
				pageNum : pageNum,
				pageSize : 10,
				name : $("#searchName").val()
			},
			success : function(data) {
				console.log(data);
				convertData(data, "outputDiv", "cart_jst");
				convertData(data, "pageShow", "pageData");
			}
		});
	}
	</script>
</body>
</html>